package com.yihu.wlyy.web.common.util;

import com.yihu.wlyy.service.app.disease.PatientDiseaseService;
import com.yihu.wlyy.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by lyr on 2016/09/13.
 */
@RestController
@RequestMapping(value = "/manage_util")
public class ManagerUtilController extends BaseController{

    @Autowired
    PatientDiseaseService diseaseService;
    @Autowired
    StringRedisTemplate redisTemplate;

    /**
     * 更新到redis
     *
     * @return
     */
    @RequestMapping(value = "/disease/to_redis")
    public String updateToRedid(){
        try{
            diseaseService.updateToRedis();
            return write(200,"更新成功");
        }catch (Exception e){
            return error(-1,"更新失败");
        }
    }

    /**
     * 更新到疾病表
     *
     * @return
     */
    @RequestMapping(value = "/disease/to_disease")
    public String updateToDisease(){
        try{
            diseaseService.updateToDisease();
            return write(200,"更新成功");
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"更新失败");
        }
    }

    @RequestMapping(value = "/disease/patient")
    public String getDiseaseFromRedis(String patient){
        try{
            return write(200,"查询成功","data",redisTemplate.opsForValue().get("disease:" + patient));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"查询失败");
        }
    }
}
